package org.flashbrighton.as3bots.views.ui.scores
{
	import flash.display.Sprite;

	import org.flashbrighton.as3bots.models.BotModel;

	public class BombCounter extends Sprite
	{
		private var _botModel:BotModel;
		private var _currentNbBombs:int;
		private var bombs:Array=new Array();

		public function BombCounter(botModel:BotModel)
		{
			_botModel=botModel;
			init();
		}

		private function init():void
		{
			_currentNbBombs=_botModel.bot.nbBombs;
			for (var j:int=0; j < _botModel.bot.nbBombs; j++)
			{
				var bomb:Sprite=new Sprite();
				// Border
				bomb.graphics.lineStyle(1, 0x202020);
				bomb.graphics.beginFill(0xFF0000, 1);
				bomb.graphics.drawCircle(0, 0, 2);
				bomb.graphics.endFill();
				bomb.x=j * 8 + 2;
				this.addChild(bomb);
				bombs.push(bomb);
			}
		}

		public function update():void
		{
			if (_currentNbBombs > _botModel.bot.nbBombs)
			{
				_currentNbBombs=_botModel.bot.nbBombs;
				this.removeChild(bombs.pop());
			}
		}

	}
}